﻿namespace Resharper.Abstractions.Daemons
{
  using System;
  using JetBrains.Annotations;
  using JetBrains.ReSharper.Psi;

  /// <summary>Defines the <see cref="SourceFile"/> class.</summary>
  public class SourceFile
  {
    #region Constants and Fields

    private readonly IPsiSourceFile sourceFile;

    #endregion

    #region Constructors and Destructors

    /// <summary>Initializes a new instance of the <see cref="SourceFile"/> class.</summary>
    /// <param name="sourceFile">The source file.</param>
    internal SourceFile([NotNull] IPsiSourceFile sourceFile)
    {
      if (sourceFile == null)
      {
        throw new ArgumentNullException("sourceFile");
      }

      this.sourceFile = sourceFile;
    }

    #endregion

    #region Properties

    /// <summary>
    /// Gets the name of the file.
    /// </summary>
    [NotNull]
    public string FileName
    {
      get
      {
        var projectFile = this.sourceFile.ToProjectFile();
        if (projectFile == null)
        {
          return string.Empty;
        }

        return projectFile.Location.ToString();
      }
    }

    /// <summary>
    /// The project file name field.
    /// </summary>
    [NotNull]
    public string ProjectFileName
    {
      get
      {
        var projectFile = this.sourceFile.ToProjectFile();
        if (projectFile == null)
        {
          return string.Empty;
        }

        var project = projectFile.GetProject();
        if (project == null)
        {
          return string.Empty;
        }

        return project.ProjectFileLocation.ToString();
      }
    }

    #endregion
  }
}